var environment=_gl.environment||"production";
var ajaxUrl={
    "local":{
        "settimeoutTime":1400,
        "dataList":_gl._host_res+"/res/js/data/userList.json",
        "updateUser":_gl._host_res+"/res/js/data/updateUser.json"
    },
    "production":{
        "settimeoutTime":0,
        "dataList":_gl._host_api+"/users",
        "updateUser":_gl._host_api+"/users"
    }
};
$(function(){
    _fridayTable.setTableTr({
        "url":ajaxUrl[environment].dataList,
        "columns":[
            {
                "fieldName":null,
                "dom":"seq"
            },
            {
                "fieldName":"name"
            },
            {
                "fieldName":"sex",
                "formatFun": _helper.sexFormat
            },
            {
                "fieldName":"mobile"
            },
            {
                "fieldName":"brithday",
                "formatFun": _helper.timeFormat
            },
            {
                "fieldName":"create_time",
                "formatFun": _helper.timeFormat
            },
            {
                "fieldName":"user_source",
                "formatFun": sourseFormat
            },
            {
                "fieldName":null,
                "dom":"6000"
            },
            {
                "fieldName":null,
                "renderFun": function (val) {
                    return '<a class="btn btn-success btn-sm btn-operation btn-update" href="#"><span class="glyphicon glyphicon-edit"></span>修改研值</a>';
                }
            }
        ]
    });
    _fridayTable.searchData();


    /*页面按钮 查询 更多 修改颜值 上一页 下一页*/
    $(document).on( 'click','a,button', function (e) {
        e.stopPropagation();
        if($(this).hasClass("btn-update")){
            //列表里面的修改颜值
            var itemId = $(this).parents("tr").find("input[type='hidden']").val();
            var yanzhi = 600;
            layer.prompt({title:"请输入研值",value:yanzhi,maxlength:10},function(val, index){
                layer.close(index);
                updateItem({"id":itemId,"yanzhi":val});
            });

        }
    });

    //修改课程
    function updateItem(obj){
        if(!obj) obj={};
        var loadingIndex = _helper.fridayLoadinFun();
        var data= JSON.stringify(obj);
        setTimeout(function(){
            $.ajax({
                type: "POST",
                url:ajaxUrl[environment].updateUser,
                data: data,
                dataType: "json"
            }).done(function(data) {
                if(data && data.code==200){
                    //
                    _helper.ajaxMessage({"message":"修改成功！"});
                }else{
                    _helper.ajaxMessage({"message":(data&&data.message)||"修改失败！"});
                }
            }).fail(function(){
                _helper.ajaxErrorTips({"tips":"修改失败，请稍后再试！"});
            }).always(function(){
                layer.close(loadingIndex);
            });
        },ajaxUrl[environment].settimeoutTime);
    }

    //用户来源格式
    function sourseFormat(str){
        if(!str) str ="";
        return str=="1"?"微信用户":"其他";
    }
});